package com.ldc.common.mvvm;

import android.os.Bundle;

import androidx.viewbinding.ViewBinding;

public abstract class BaseMvvmActivity<VB extends ViewBinding, VM extends ViewModelBase> extends BaseActivity<VB> {
    protected VM viewModel;

    protected abstract VM initViewModel();

    @Override
    protected VB loadViewBinding() {
        VB vb = super.loadViewBinding();
        viewModel = initViewModel();
        if (null != viewModel) {
            this.getLifecycle().addObserver(viewModel);
        }
        return vb;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (null != viewModel) {
            this.getLifecycle().removeObserver(viewModel);
        }
    }
}
